//
//  ZZMusicModel.m
//  ZZBlue
//
//  Created by stonesMonkey on 2017/9/17.
//  Copyright © 2017年 stonesMonkey. All rights reserved.
//

#import "ZZMusicModel.h"

@implementation ZZMusicModel

-(void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:self.musicName forKey:@"musicName"];
    [aCoder encodeObject:self.path forKey:@"path"];
    [aCoder encodeInteger:self.duration forKey:@"duration"];
    [aCoder encodeObject:self.auther forKey:@"auther"];
    [aCoder encodeObject:self.imagePath forKey:@"imagePath"];
   [aCoder encodeBool:self.isSelect forKey:@"isSelect"];
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        self.isPlayer =NO;
        self.musicName = [aDecoder decodeObjectForKey:@"musicName"];
        self.path = [aDecoder decodeObjectForKey:@"path"];
        self.duration = [aDecoder decodeIntegerForKey:@"duration"];
        self.auther = [aDecoder decodeObjectForKey:@"auther"];
        self.imagePath = [aDecoder decodeObjectForKey:@"imagePath"];
        self.isSelect = [aDecoder decodeBoolForKey:@"isSelect"];
    }
    return self;
}

- (instancetype)initWithDict:(NSDictionary *)dict {

    if (self= [super init]) {

        [self setValuesForKeysWithDictionary:dict];
        self.path = [NSURL URLWithString:dict[@"path"]];
        self.musicName = dict[@"music_name"];
        self.isSelect = dict[@"is_select"];
    }

    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{};

+ (NSMutableArray <ZZMusicModel*>*)modelsForNSArray:(NSArray *)dicts {

    NSMutableArray *mtbArr = [NSMutableArray array];
    for (NSDictionary *dict in dicts) {

        ZZMusicModel *model = [[self alloc]initWithDict:dict];
        [mtbArr addObject:model];
    }
    return mtbArr;
}

@end
